/*  
 * 常规cookie操作
 * @Author: beautifulHao 
 * @Date: 2019-07-17 14:57:12
 * @Last Modified by: beautifulHao
 * @Last Modified time: 2019-08-31 11:15:16
 */
export default {
  get (key) {
    if (key) {
      var name = key + "=";
      var decodedCookie = decodeURIComponent(document.cookie);
      var ca = decodedCookie.split(';');
      for(var i = 0; i <ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) === ' ') {
              c = c.substring(1);
           }
           if (c.indexOf(name) === 0) {
              return c.substring(name.length, c.length);
           }
       }
      return "";
    }
  },
  set (key, value, exp) {
    if (key) {
      if (exp instanceof Date) {
        document.cookie = escape(key) + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/"
        var expires = "expires="+ exp.toUTCString();
        document.cookie = key + "=" + value + ";" + expires + ";path=/";
      }
      else {
        document.cookie = key + "=" + value+ ";path=/"
      }
    }

  },
  remove (key) {
    if (!key) {
      return
    }
    document.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"
  }
}